/* jshint indent: 2 */
module.exports = (app) => {
  const sequelize = app.model;
  const DataTypes = app.Sequelize.DataTypes;
  const Active = sequelize.define('active', {
    id: {
      type: DataTypes.UUID,
      allowNull: false,
      primaryKey: true,
    },
    status: {
      field: 'status',
      type: DataTypes.INTEGER(1),
      defaultValue: 0,
      comment: '状态，0:未使用，1:已使用',
    },
  }, {
    tableName: 'active',
    createdAt: 'create_time', // 记录创建时间
    updatedAt: 'update_time', // 记录更新时间
    freezeTableName: true, // 不允许修改表名
  });

  Active.associate = () => {
    app.model.Active.belongsTo(app.model.User, {
      as: 'user',
      foreignKey: 'userId',
    });
  };
  return Active;
};
